home *** CD-ROM | disk | FTP | other *** search
- Newsgroups: comp.lang.c++
- Path: cdf.toronto.edu!news
- From: p a u l <a209dowm@cdf.utoronto.ca>
- Subject: Re: file descriptors and fstreams...
- Content-Type: text/plain; charset=us-ascii
- Message-ID: <DpI5sI.EGx@cdf.toronto.edu>
- Sender: news@cdf.toronto.edu (Usenet News)
- Nntp-Posting-Host: sat
- Content-Transfer-Encoding: 7bit
- Organization: Computing Disciplines Facility, University of Toronto
- References: <4k780i$dd5@beyond.escape.com>
- Mime-Version: 1.0
- Date: Sun, 7 Apr 1996 17:26:39 GMT
- X-Mailer: Mozilla 1.1N (X11; I; SunOS 5.3 sun4c)
- X-Url: news:4k780i$dd5@beyond.escape.com
-
- >Hi I'm a very beginner c++ programmer, although I've been doing C for a
- >while. I know there's a C function called fdopen which takes a file
- >descriptor and creates a stream for it so you can use fprintf, fscanf,
- >and all that other good stuff. Is there a similar function (or whatever)
- >that takes a file descriptor and does something to let you use << and >>
- >with it?
-
- I think the equivalent to fdopen() is this constructor:
-
- ifstream::ifstream (int fd) // fd is an already open file descriptor
-
- so you would use:
- ifstream in_file(5); // using file descriptor 5
-
- to create a new ifstream object that reads from an already open file
- descriptor.
- see this url for more info on iostreams with g++:
- http://www.cygnus.com/doc/iostream_24.html#SEC24
-
- I haven't been able to get it to work myself though, perhaps it's because I was
- trying to use it on a file descriptor that is actually a pipe. can anyone tell
- m if that should work? my (unsatisfactory) workaround is to write to a string
- with an strstream object and then use write() to send that to the file
- descriptor. is there a better way?
-
- Paul.
-
-